﻿using Cdx.Ui.App_Start;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Web.Http;

namespace Cdx.Ui
{
    public static class WebApiConfig
    {
        [SecuritySafeCritical]
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            //HandleDomainExceptions();
        }

        [SecuritySafeCritical]
        public static void HandleDomainExceptions()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }
        
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Logger.Log.ErrorFormat("Domain failure", e);    
        }
    }
}
